import opennsfw2 as n2


# 将自动下载预训练模型 open_nsfw_weights.h5 到 C:\Users\Administrator\.opennsfw2\weights
# pip install opennsfw2

def predictImg(imagePath):
    # 单张预测
    nsfw_probability = n2.predict_image(imagePath)
    nsfw_probability = int(nsfw_probability * 100)
    print(str(nsfw_probability) + "%")
    return nsfw_probability

    # 0.16282974183559418

    # 批量预测
    # image_paths = ['1.jpg', '2.jpg']
    # nsfw_probabilities = n2.predict_images(image_paths)
    # print(nsfw_probabilities)
    # [0.16282965242862701, 0.8638442158699036]


if __name__ == '__main__':
    print(predictImg(r"F:\trainData\image\0a3f3de07e1f4dbdae5d5c9b541a2c9e.jpeg"))
